home *** CD-ROM | disk | FTP | other *** search
- /*
- File: SoundHandling.h
-
- Contains: CSounder, CPlayer, and CRecorder classes implementation.
-
- Written by: Andrey Dolgachev
-
- Copyright: © 1994,95 by Apple Computer, Inc., all rights reserved.
- */
-
-
- #ifndef _SOUNDHANDLING_
- #define _SOUNDHANDLING_
-
- // -- Macintosh Includes --
-
- #ifndef __SOUND__
- #include <Sound.h>
- #endif
-
- #ifndef __SOUNDINPUT__
- #include <SoundInput.h>
- #endif
-
- //------------------------------------------------------------------------------
- // Class Definitions
- //------------------------------------------------------------------------------
-
- // Superclass for common functionality between recording and playing
- class CSounder
- {
- public:
-
- CSounder();
- ~CSounder();
-
- ODBoolean IsInitialized();
- ODBoolean IsPaused();
- ODBoolean HasSound();
-
- ODFrame* GetFrame();
- void SetFrame(ODFrame* f);
-
- ODHandle GetSound();
- void SetSound(ODHandle d);
- void DisposeSound();
-
- ODSShort GetLevel();
- ODULong GetTime();
-
- virtual ODBoolean IsCompleted();
-
- protected:
-
- virtual ODBoolean Initialize();
- virtual ODBoolean DeInitialize();
-
- // Virtual methods handle time-management at this level
- virtual ODBoolean Start(ODFrame* frame);
- virtual ODBoolean Stop();
- virtual ODBoolean Pause();
- virtual ODBoolean Resume();
-
- ODBoolean IsSounding();
-
- // Data members used needed by both superclass and its subclasses
- ODHandle fSoundHandle;
- ODSShort fMeterLevel;
-
- private:
-
- // Boolean variables for state information
- ODBoolean fInitialized;
- ODBoolean fSounding;
- ODBoolean fPaused;
-
- // External data objects
- ODFrame* fFrame;
-
- // Time management variables
- ODULong fStartSecs;
- ODULong fCurrentTime;
- ODULong fPausedSecs;
- ODULong fPauseStart;
- ODULong fPauseEnd;
-
- };
-
- // Class for playing sound
- class CPlayer : public CSounder
- {
- public:
-
- CPlayer();
- ~CPlayer();
-
- virtual ODBoolean Initialize();
- virtual ODBoolean DeInitialize();
-
- virtual ODBoolean Start(ODFrame* frame);
- virtual ODBoolean Stop();
- virtual ODBoolean Pause();
- virtual ODBoolean Resume();
-
- ODBoolean IsPlaying();
- virtual ODBoolean IsCompleted();
-
- private:
-
- SndChannelPtr fSoundChannel;
- ODSLong fSoundChannelRate;
-
- };
-
- // Class for recording sound
- class CRecorder : public CSounder
- {
- public:
-
- CRecorder();
- ~CRecorder();
-
- virtual ODBoolean Initialize();
- virtual ODBoolean DeInitialize();
-
- virtual ODBoolean Start(ODFrame* frame);
- virtual ODBoolean Stop();
- virtual ODBoolean Pause();
- virtual ODBoolean Resume();
-
- ODSLong GetMaxTime(ODSLong MaxSize, OSType rQuality);
-
- void SetQuality(OSType rQuality);
- OSType GetQuality();
-
- ODBoolean IsRecording();
- virtual ODBoolean IsCompleted();
-
- private:
-
- ODSLong fSoundDevice;
- OSType fRecordingQuality;
- SPB sPar;
- };
-
- //------------------------------------------------------------------------------
- // Inline methods
- //------------------------------------------------------------------------------
-
- //==============================================================================
- // CSounder
- //==============================================================================
-
- inline ODBoolean CSounder::IsInitialized()
- {
- return fInitialized;
- }
-
- inline ODBoolean CSounder::IsPaused()
- {
- return fPaused;
- }
-
- inline ODBoolean CSounder::HasSound()
- {
- return (fSoundHandle != kODNULL);
- }
-
- inline ODFrame* CSounder::GetFrame()
- {
- return fFrame;
- }
-
- inline void CSounder::SetFrame(ODFrame* f)
- {
- fFrame = f;
- }
-
- inline ODHandle CSounder::GetSound()
- {
- return fSoundHandle;
- }
-
- inline void CSounder::SetSound(ODHandle d)
- {
- this->DisposeSound();
- fSoundHandle = d;
- }
-
- inline ODSShort CSounder::GetLevel()
- {
- return fMeterLevel;
- }
-
- inline ODULong CSounder::GetTime()
- {
- return fCurrentTime;
- }
-
- inline ODBoolean CSounder::Initialize()
- {
- fInitialized = kODTrue;
- return fInitialized;
- }
-
- inline ODBoolean CSounder::DeInitialize()
- {
- fInitialized = kODFalse;
- return !fInitialized;
- }
-
- inline ODBoolean CSounder::IsSounding()
- {
- return fSounding;
- }
-
- //==============================================================================
- // CPlayer
- //==============================================================================
-
- inline ODBoolean CPlayer::IsPlaying()
- {
- return CSounder::IsSounding();
- }
-
- //==============================================================================
- // CRecorder
- //==============================================================================
-
- inline ODBoolean CRecorder::IsRecording()
- {
- return CSounder::IsSounding();
- }
-
- inline OSType CRecorder::GetQuality()
- {
- return fRecordingQuality;
- }
-
- #endif
-